<?php

/***

LZRoster: A roster for World of Warcraft.
Copyright (C) 2007  Emmanuel Cron

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

***/

require_once "class/Load.class.php";
require_once "class/WowTable.class.php";
require_once "class/Config.class.php";
require_once "class/Inputs.class.php";
require_once "class/StatusRoster.class.php";
require_once "class/Localization.class.php";
require_once "class/CraftContainer.class.php";
require_once "class/CraftDisplayer.class.php";
require_once "class/ObjectContainer.class.php";
require_once "class/TradeskillContainer.class.php";

// For loading information in footer
Load::GetInstance();

// Outdated characters purge
CharacterManager::GetInstance()->DeleteCharacters(CharacterManager::GetInstance()->GetOutdatedCharactersNames());

// Session initialization
SessionRoster::GetInstance();

// Set up group_concat_max_len
ObjectContainer::GetInstance();

if (Inputs::GetInstance()->Get('t') != null
	and TradeskillContainer::GetInstance()->HasTradeskillId(Inputs::GetInstance()->Get('t'))
	and !TradeskillContainer::GetInstance()->IsTradeskillHiddenById(Inputs::GetInstance()->Get('t')) ) {
	$craft_displayer = CraftDisplayer::GetInstance();
	
	$wow_table = new WowTable( Localization::GetInstance()->Get('crafts list') );
	$wow_table->AddColumn( Localization::GetInstance()->Get('name'), null, 300 );
	$wow_table->AddColumn( Localization::GetInstance()->Get('reagents'), null, 300 );
	$wow_table->AddColumn( Localization::GetInstance()->Get('characters') );
	
	foreach(CraftContainer::GetInstance()->GetCraftsByTradeskillId(Inputs::GetInstance()->Get('t'), Inputs::GetInstance()->Get('s')) as $craft) {
		if ( $wow_table->HasSubSection($craft->GetCategoryName()) == false ) {
			$wow_table->AddSubsection($craft->GetCategoryName());
		}
		
		$wow_table->AddLine($craft->GetCategoryName(), array(
			$craft_displayer->Name($craft),
			$craft_displayer->Reagents($craft),
			$craft_displayer->Characters($craft),
		));
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
	<head>
		<title>LZRoster<?php echo Config::GetInstance()->HasRosterTitle() ?  " - ".Config::GetInstance()->GetRosterTitle() : null; ?></title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" media="screen" type="text/css" href="styles/_.css" />
		<link rel="stylesheet" media="screen" type="text/css" href="styles/tradeskills.css" />
		<link rel="stylesheet" media="screen" type="text/css" href="styles/tooltip.css" />
		<link rel="stylesheet" media="screen" type="text/css" href="styles/wowtable.css" />
		<script src="http://www.wowhead.com/widgets/power.js"></script>
		<script type="text/javascript" src="js/display.js"></script>
		
		<?php
		if ( isset($wow_table) )
		{
		?>
		
		<script type="text/javascript">
			function doSearch()
			{
				if ( document.getElementById('searchInput').value == '' )
				{
					return false;
				}
				
				document.location.href = '?t=<?php echo TradeskillContainer::GetInstance()->GetTradeskillById(Inputs::GetInstance()->Get('t'))->GetId(); ?>'+'&'+'s='+document.getElementById('searchInput').value;
			}
		</script>
		
		<?php
		}
		?>
		
	</head>
	<body>
		
		<?php require_once "inc/head.php"; ?>
		<?php require_once "inc/hmenu.php"; ?>
		
		<p id="tradeskillmenu">
			
			<?php echo Localization::GetInstance()->Get('choose'); ?>
			
			<?php
			$i=0;
			foreach (TradeskillContainer::GetInstance()->GetAllTradeskills() as $tradeskill)
			{
				if (!$tradeskill->IsHidden()) {
				?>
				
				<img src="img/<?php echo $tradeskill->GetIcon(); ?>" alt="" />
				<a href="?t=<?php echo $tradeskill->GetId(); ?>"><?php echo $tradeskill->GetNameLiteral(); ?></a>
				
				<?php
				$i++;
				}
				
				if ($i%6 == 0)
				{
					echo "<br/>";
				}
			}
			?>
			
		</p>
		
		<?php
		if (StatusRoster::GetInstance()->HasMessage())
		{
		?>
			<h2><?php echo Localization::GetInstance()->Get('tradeskills'); ?></h2>
			
			<p>
				<?php echo Localization::GetInstance()->Get('this page produced some messages. please refer to the following lines'); ?>
			</p>
			
			<?php echo StatusRoster::GetInstance()->GetStack_InList(); ?>
			
			<p>
				<?php echo Localization::GetInstance()->Get('you can refresh the page %s and try again', "tradeskills.php"); ?>
			</p>
			
		<?php
		}
		elseif ( isset($wow_table) )
		{
		?>
		
		<p style="float: right; margin-top: 5px;">
			<input type="text" id="searchInput" onkeypress="if (event.keyCode == 13 || event.which == 13) { doSearch(); }" />
			<a href="javascript:;" onclick="doSearch();">
				<img src="img/magnify.png" alt="" style="vertical-align: bottom;" />
			</a>
		</p>
		
		<h2>
			<img src="img/<?php echo TradeskillContainer::GetInstance()->GetTradeskillById(Inputs::GetInstance()->Get('t'))->GetBigIcon(); ?>" alt="" style="vertical-align: middle;" />
			<?php echo TradeskillContainer::GetInstance()->GetTradeskillById(Inputs::GetInstance()->Get('t'))->GetNameLiteral(); ?>
		</h2>
		
		<?php
		if ( Inputs::GetInstance()->HasGetData('s') )
		{
		?>
		
		<p style="text-align: center;">
			<span style="color: #ffb019; font-style: italic; font-size: 1.2em; font-weight: bold;">
				<?php echo Localization::GetInstance()->Get('search results for %s', utf8_encode(Inputs::GetInstance()->Get('s'))); ?><br />
			</span>
			<?php echo Localization::GetInstance()->Get('go back to %s all the crafts', "tradeskills.php?t=".Inputs::GetInstance()->Get('t')); ?>
		</p>
		
		<?php
		}
		?>
		
		<?php $wow_table->GetAndPrintTable(true); ?>
		
		<?php
		}
		?>
		
		<?php require_once "inc/foot.php"; ?>
		
	</body>
</html>